
#include <string>
#include <fstream>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

const string Episode("Episode");
const string failed("failed");
const string succeeded("succeded");

int main(int argc, char **argv){

	std::cout<<"usage:: input output"<<std::endl;

	string input = argv[1];
	string output = argv[2];

	std::ofstream successOut;
	successOut.open(output.c_str());

	  std::ifstream output_log(argv[1]);
//	  output_log.open(input.c_str());

	  int curNumEpisode = 0;
	  int numSuccessSoFar = 0;
	  int lastNumEpisode = -1;

	  string s, last_s;

	  string line;
	  std::cout<<" file opened "<<std::endl;
	  while(getline(output_log, line)){
		  istringstream iss2(line, istringstream::in);
                  
                  while (iss2 >> s) {
		       if((s.compare(failed)== 0) || (s.compare(succeeded) == 0)) {
			  curNumEpisode = atoi(last_s.c_str());
			  if(lastNumEpisode < curNumEpisode){
				  if(s.compare(succeeded) == 0) {
					  numSuccessSoFar++;
				  }
				//  std::cout<<curNumEpisode<<"\t"<<numSuccessSoFar<<std::endl;
				  successOut<<curNumEpisode<<"\t"<<numSuccessSoFar<<std::endl;
			  }
			  lastNumEpisode = curNumEpisode;

                               break;
		       }
	               last_s = s;
                  }
	  }

	  output_log.close();
	  successOut.close();

	  return 0;
}
